var express = require('express')
var path = require('path')
var mongoose = require('mongoose')
var cookieParser = require('cookie-parser')
var session = require('express-session')
var mongoStore = require('connect-mongo')(session)
var port = process.env.PORT || 3000
var app = express() // 启动WEB服务器

var dbConn = 'mongodb://localhost/imooc'
mongoose.connect(dbConn)

app.set('views', './app/views/pages')
app.set('view engine', 'jade')
app.use(cookieParser())
app.use(session({  
  resave:false,//添加这行  
  saveUninitialized: true,//添加这行   
  secret: 'imooc',
  store: new mongoStore({
  	url: dbConn,
  	collection: 'sessions'
  })
})) 

if ('development' === app.get('env')){
	app.set('showStackError', true)
	//app.use(express.logger(':method :url :status'))
	app.locals.pretty=true
	mongoose.set('debug', true)
}

require('./config/routes')(app)

app.listen(port)
app.locals.moment = require('moment')
app.use(express.static(path.join(__dirname, 'public')))

// PORT=4000 node app.js
console.log('imooc started on port: ' + port)





